<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // function greatestCommonDivisor(a, b){
        //     let divisor = 2, res = 1
        //     if(a < 2 || b < 2){
        //         return 1
        //     }
        //     while(a >= divisor && b >= divisor){
        //         if(a % divisor === 0 && b % divisor === 0){
        //             res = divisor
        //         }
        //         divisor++;
        //     }
        //     return res
        // }
        // console.log(greatestCommonDivisor(8, 4));
        function greatestCommonDivisor(a, b){
            if(b === 0){
                return a
            }else{
                return greatestCommonDivisor(b, a%b)
            }
        }
        console.log(greatestCommonDivisor(8, 4));
    </script>
</body>
</html>